package com.freight.base.controller;

import com.freight.base.entity.PlatformRules;
import com.freight.base.service.PlatformRulesService;
import com.freight.base.vo.PlatformRulesVo;
import com.freight.core.common.utils.PageUtil;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.PageVo;
import com.freight.core.common.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import java.util.List;


@Api(description = "法律条款与平台规则接口")
@RequestMapping("/freight/platformRules")
@RestController
@Slf4j
public class PlatformRulesController {

    @Autowired
    private PlatformRulesService platformRulesService;


    @PostMapping(value = "/savePlatformRules")
    @ApiOperation(value = "保存文件")
    public Result<String> savePlatformRules(@RequestBody String content) {
        platformRulesService.savePlatformRules( content);
        return new ResultUtil<String>().setData("操作成功");
    }

    @RequestMapping(value = "/deletePlatformRules", method = RequestMethod.POST)
    @ApiOperation(value = "根据id删除文件")
    public Result<String> deletePlatformRules(Long id) {
        platformRulesService.deletePlatformRules( id);
        return new ResultUtil<String>().setData("操作成功");

    }

    @RequestMapping(value = "/getPlatformRulesId", method = RequestMethod.POST)
    @ApiOperation(value = "根据id获取文件")
    public Result<PlatformRulesVo> getPlatformRulesId(Long id) {
        PlatformRulesVo platformRules=platformRulesService.getPlatformRulesId(id);
        return new ResultUtil<PlatformRulesVo>().setData(platformRules);
    }

    @RequestMapping(value = "/getPlatformRulesPage", method = RequestMethod.GET)
    @ApiOperation(value = "获取文件分页列表")
    public Result<Page<PlatformRules>> getPlatformRulesPage(PageVo page) {
        Page<PlatformRules> list = platformRulesService.getPlatformRulesPage(PageUtil.initPage(page));
        return new ResultUtil<Page<PlatformRules>>().setData(list);
    }

    @RequestMapping(value = "/getPlatformRulesList", method = RequestMethod.POST)
    @ApiOperation(value = "根据用户类型获取文件列表")
    public Result<List<PlatformRules>> getPlatformRulesList() {
        List<PlatformRules> page = platformRulesService.getPlatformRulesList();
        return new ResultUtil<List<PlatformRules>>().setData(page);
    }

}
